indexManage
<!-- 设备管理-设备列表页面 -->
<template>
  <div class="app-container">
    <px-form v-show="showSearch" ref="queryRef" class="custom-form-ui" :model="queryParams" :inline="true" label-width="90px">
      <px-form-item label="指标名称">
        <px-input v-model="queryParams.name" :maxlength="50" placeholder="请输入" clearable />
      </px-form-item>
      <px-form-item label="所属厂区">
        <!-- <px-select v-model="queryParams.level" placeholder="请选择" clearable style="width: 240px" filterable>
          <px-option v-for="dict in liquidList" :key="dict.id" :label="dict.itemName" :value="dict.itemName" />
        </px-select> -->
        <px-select v-model="queryParams.level" :disabled="facDisabled" placeholder="请选择" clearable filterable>
          <px-option v-for="item in facList" :key="item.itemName" :label="item.itemName" :value="item.itemValue" />
        </px-select>
      </px-form-item>
      <px-form-item label="指标计算周期">
        <px-select v-model="queryParams.cycle" placeholder="请选择" clearable style="width: 240px" filterable>
          <px-option v-for="dict in cycleList" :key="dict.name" :label="dict.name" :value="dict.value" />
        </px-select>
      </px-form-item>
      <px-button style="margin-top: -17px" type="primary" icon="" @click="handleQuery('search')">搜索</px-button>
      <px-button style="margin-top: -17px" icon="" @click="resetQuery">重置</px-button>
    </px-form>

    <px-row :gutter="10" class="mb8">
      <px-col :span="1.5">
        <px-button v-has="'INDEXMANAGE_ADD'" type="primary" icon="" @click="handleAdd">新增</px-button>
      </px-col>
    </px-row>

    <px-table v-if="!addVisible" v-loading="loading" :data="typeList" height="calc(100vh - 319px)" border>
      <px-table-column label="序号" fixed="left" type="index" width="70">
        <template #default="{ $index }">
          {{ $index + 1 + (queryParams.pageNum - 1) * queryParams.pageSize }}
        </template>
      </px-table-column>
      <px-table-column label="指标名称" prop="name" width="240">
        <template #default="scope">
          <span>{{ scope.row.name }}</span>
        </template>
      </px-table-column>

      <px-table-column label="所属厂区" prop="level">
        <template #default="scope">
          <span>{{ scope.row.level }}</span>
        </template>
      </px-table-column>

      <px-table-column label="监控周期" prop="cycle">
        <template #default="scope">
          <span>{{ scope.row.cycle }}</span>
        </template>
      </px-table-column>
      <px-table-column label="执行时间" min-width="186">
        <template #default="scope">
          <span v-if="scope.row.cycle == '日'">{{ scope.row.startTime.split(" ")[0] }}~{{ scope.row.endTime.split(" ")[0] }}</span>
          <span v-if="scope.row.cycle == '月'">{{ scope.row.startTime.slice(0, 7) }}~{{ scope.row.endTime.slice(0, 7) }}</span>
          <span v-if="scope.row.cycle == '年'">{{ scope.row.startTime.slice(0, 4) }}~{{ scope.row.endTime.slice(0, 4) }}</span>
        </template>
      </px-table-column>
      <px-table-column label="监控阈值">
        <template #default="scope">
          <span v-if="scope.row.limitMethod == '百分比'">{{ scope.row.limitValue }}%</span>
          <span v-else> {{ scope.row.limitMin }}~{{ scope.row.limitMax }} </span>
        </template>
      </px-table-column>
      <px-table-column label="指标公式" prop="cycle">
        <template #default="scope">
          <px-tooltip
            class="box-item"
            :content="`[${scope.row.codeName}]x[${scope.row.coefficient}]x[${scope.row.emissionFactorName}]`"
            placement="top"
          >
            <span style="color: #4e8ef6">查看</span></px-tooltip
          >
        </template>
      </px-table-column>

      <px-table-column label="创建时间" min-width="160" prop="createTime">
        <template #default="scope">
          <span>{{ scope.row.createTime }}</span>
        </template>
      </px-table-column>

      <px-table-column label="创建人" width="120" prop="createByName">
        <template #default="scope">
          <span>{{ scope.row.createByName }}</span>
        </template>
      </px-table-column>
      <px-table-column label="修改时间" min-width="160" prop="updateTime">
        <template #default="scope">
          <span>{{ scope.row.updateTime }}</span>
        </template>
      </px-table-column>
      <px-table-column label="修改人" width="120" prop="updateByName">
        <template #default="scope">
          <span>{{ scope.row.updateByName }}</span>
        </template>
      </px-table-column>
      <px-table-column label="操作" align="center" width="140">
        <template #default="scope">
          <px-button v-has="'INDEXMANAGE_DETAIL'" link type="primary" @click="handleDetail(scope.row.id)">
            <px-tooltip class="box-item" content="详情" placement="top">
              <px-icon>
                <Tickets />
              </px-icon> </px-tooltip
          ></px-button>
          <px-button v-if="scope.row.status != 'INVALID'" v-has="'INDEXMANAGE_EDITOR'" link type="primary" @click="handleEditor(scope.row.id)">
            <px-tooltip class="box-item" content="编辑" placement="top">
              <px-icon>
                <EditPen />
              </px-icon> </px-tooltip
          ></px-button>
          <px-button v-if="scope.row.status != 'INVALID'" v-has="'INDEXMANAGE_DELETE'" link type="danger" @click="handleDelete(scope.row)"
            ><px-tooltip class="box-item" content="删除" placement="top">
              <px-icon>
                <Delete />
              </px-icon> </px-tooltip
          ></px-button>
        </template>
      </px-table-column>
      <template #empty>
        <px-empty :image-size="150" />
      </template>
    </px-table>

    <pagination
      v-if="!equipopen && !equipopenDetail"
      v-show="total > 0"
      v-model:page="queryParams.pageNum"
      v-model:limit="queryParams.pageSize"
      style="margin-bottom: -10px"
      :total="total"
      @pagination="getList"
    />

    <!-- 添加或修改参数配置对话框 -->
    <px-dialog v-model="innerVisible" width="1372" title="排放因子库" append-to-body align-center>
      <px-form v-show="showSearch" class="custom-form-ui" :model="queryParams" :inline="true" label-width="90px">
        <px-form-item label="排放因子名称">
          <px-input v-model="queryParams2.emissionFactorName" placeholder="请输入排放因子名称" clearable />
        </px-form-item>
        <px-form-item label="排放因子来源">
          <px-select v-model="queryParams2.factorSource" placeholder="请选择" clearable style="width: 240px" filterable>
            <px-option v-for="dict in SourceList" :key="dict.itemName" :label="dict.itemName" :value="dict.itemName" />
          </px-select>
        </px-form-item>
        <!-- <px-form-item label="年份">
          <px-date-picker v-model="queryParams2.releaseYear" type="year" value-format="YYYY" placeholder="请选择年份" />
        </px-form-item> -->
        <px-button style="margin-top: -17px" type="primary" icon="" @click="handleQuery2('search')">搜索</px-button>
        <px-button style="margin-top: -17px" icon="" @click="resetQuery2">重置</px-button>
      </px-form>
      <px-table
        v-loading="loading"
        :data="rukuList"
        height="calc(100vh - 339px)"
        show-overflow-tooltip
        highlight-current-row
        border
        @current-change="handleSelectionChange2"
      >
        <!-- <px-table-column type="selection" width="40" /> -->
        <px-table-column label="" width="40">
          <template #default="scope">
            <span>
              <px-radio v-model="selectrow" :label="scope.row" size="large" @change="handelRadio(scope.row)">{{
                scope.row.xx ? scope.row.xx : " "
              }}</px-radio></span
            >
          </template>
        </px-table-column>
        <px-table-column label="排放因子名称" width="160" prop="inboundNumber">
          <template #default="scope">
            <span>{{ scope.row.name }}</span>
          </template>
        </px-table-column>
        <px-table-column label="产生的GHG种类" prop="gasType">
          <template #default="scope">
            <span>{{ scope.row.gasType }}</span>
          </template>
        </px-table-column>
        <px-table-column label="CO₂e排放因子" prop="value">
          <template #default="scope">
            <span>{{ scope.row.value }}</span>
          </template>
        </px-table-column>
        <px-table-column label="CO₂e排放因子单位" prop="unit">
          <template #default="scope">
            <span>{{ scope.row.unit ? scope.row.unit : "-" }}{{ scope.row.wasteUnit }}</span>
          </template>
        </px-table-column>
        <px-table-column label="排放因子来源" prop="factorSource">
          <template #default="scope">
            <span>{{ scope.row.factorSource ? scope.row.factorSource : "-" }}{{ scope.row.wasteUnit }}</span>
          </template>
        </px-table-column>
        <!-- <px-table-column label="发布年份" prop="releaseYear">
          <template #default="scope">
            <span>{{ scope.row.releaseYear }}</span>
          </template>
        </px-table-column> -->
        <template #empty>
          <px-empty :image-size="150" />
        </template>
      </px-table>

      <pagination
        v-show="total2 > 0"
        v-model:page="queryParams2.pageNum"
        v-model:limit="queryParams2.pageSize"
        style="margin-bottom: -10px"
        :total="total2"
        @pagination="getRukuList"
      />
      <template #footer>
        <span class="dialog-footer">
          <px-button @click="innerVisible = false">取消</px-button>
          <px-button type="primary" @click="saveYinziku()"> 确定 </px-button>
        </span>
      </template>
    </px-dialog>
    <px-scrollbar v-if="addVisible" class="addEquip">
      <px-button style="margin-left: 24px" type="primary" :icon="ArrowLeft" @click="equipopenDetailcancel">返回</px-button>
      <px-form
        ref="detailruleFormRef"
        :disabled="fromdisable"
        :rules="rules"
        :model="equipdata"
        :inline="true"
        class="demo-form-inline"
        label-width="160px"
      >
        <div
          class="box-card1"
          :style="{
            height: jibenxinxiFlg == true ? '' : '42px',
            overflow: jibenxinxiFlg == false ? 'hidden' : 'visible'
          }"
        >
          <div class="card-header" @click="setqingdanFlg()">
            <div class="card-title">指标信息</div>
            <div class="card-main">
              <px-icon v-if="!jibenxinxiFlg">
                <ArrowDown />
              </px-icon>
              <px-icon v-else>
                <ArrowUp />
              </px-icon>
            </div>
          </div>
          <div class="form-div">
            <px-row>
              <px-col :span="12">
                <px-form-item label="指标名称" prop="name">
                  <px-input v-model="equipdata.name" :maxlength="60" placeholder="请输入指标名称" clearable />
                </px-form-item>
              </px-col>
              <px-col :span="12">
                <px-form-item label="所属厂区" prop="level">
                  <px-select
                    v-model="equipdata.level"
                    :disabled="facDisabled"
                    placeholder="请选择"
                    style="width: calc(100% - 100px)"
                    clearable
                    filterable
                  >
                    <px-option v-for="item in facList2" :key="item.itemName" :label="item.itemName" :value="item.itemValue" />
                  </px-select>
                </px-form-item>
              </px-col>
            </px-row>
            <px-row>
              <px-col :span="12">
                <px-form-item label="计算周期" prop="cycle">
                  <px-select
                    v-model="equipdata.cycle"
                    placeholder="请选择计算周期"
                    clearable
                    style="width: calc(100% - 100px)"
                    filterable
                    @change="setcycle"
                  >
                    <px-option v-for="dict in cycleList" :key="dict.name" :label="dict.name" :value="dict.value" />
                  </px-select>
                </px-form-item>
              </px-col>
              <px-col v-if="equipdata.cycle == '日'" :span="12">
                <px-form-item label="执行时间" style="width: calc(100% - 100px)" prop="dateRange">
                  <px-date-picker
                    v-model="equipdata.dateRange"
                    type="daterange"
                    start-placeholder="开始时间"
                    end-placeholder="结束时间"
                    format="YYYY-MM-DD"
                    value-format="YYYY-MM-DD"
                    :default-time="defaultTime"
                  />
                </px-form-item>
              </px-col>
              <px-col v-if="equipdata.cycle == '月'" :span="12">
                <px-form-item label="执行时间" style="width: calc(100% - 100px)" prop="dateRange">
                  <px-date-picker
                    v-model="dateRange"
                    type="monthrange"
                    range-separator="-"
                    start-placeholder="开始月份"
                    end-placeholder="结束月份"
                    placeholder="请选择"
                    format="YYYY-MM"
                    value-format="YYYY-MM"
                    @change="settime"
                  />
                </px-form-item>
              </px-col>
              <px-col v-if="equipdata.cycle == '年'" :span="12">
                <px-form-item label="执行时间" style="width: calc(100% - 100px)" prop="dateRange">
                  <yearPicker
                    style="border: 1px solid #ccc"
                    :labelWidth="0"
                    labelText=""
                    :initYear="dateValue"
                    @updateTimeRange="updateStatisticYear"
                  />
                </px-form-item>
              </px-col>
            </px-row>
            <px-row>
              <px-col :span="12">
                <px-form-item label="限值方式" prop="limitMethod">
                  <px-radio-group v-model="equipdata.limitMethod" class="ml-4" @change="clearnum">
                    <px-radio label="百分比" size="large">百分比</px-radio>
                    <px-radio label="数值" size="large">数值</px-radio>
                  </px-radio-group>
                </px-form-item>
              </px-col>
              <px-col v-if="equipdata.limitMethod == '百分比'" :span="12">
                <px-form-item label="限值百分比" prop="limitValue">
                  <px-input-number
                    v-model="equipdata.limitValue"
                    :min="0"
                    :max="99999.99999"
                    controls-position="right"
                    :precision="2"
                    style="width: calc(100% - 100px)"
                    placeholder="请输入"
                    clearable
                  />
                </px-form-item>
              </px-col>
              <px-col v-else :span="12">
                <px-form-item label="限值数值">
                  <px-input-number
                    v-model="equipdata.limitMin"
                    :min="0"
                    :max="99999999"
                    controls-position="right"
                    :precision="2"
                    style="width: calc(50% - 60px)"
                    placeholder="请输入"
                    clearable
                  />
                  <span style="margin: 0 5px">~</span>
                  <px-input-number
                    v-model="equipdata.limitMax"
                    :min="0"
                    :max="99999999"
                    controls-position="right"
                    :precision="2"
                    style="width: calc(50% - 60px)"
                    placeholder="请输入"
                    clearable
                  />
                </px-form-item>
              </px-col>
            </px-row>
          </div>
        </div>

        <div
          class="box-card2"
          :style="{
            height: jiqicanshuFlg == true ? '' : '42px'
          }"
        >
          <div class="card-header" @click="setjiqicanshuFlg()">
            <div class="card-title">计算公式</div>
            <div class="card-main">
              <px-icon v-if="!jiqicanshuFlg">
                <ArrowDown />
              </px-icon>
              <px-icon v-else>
                <ArrowUp />
              </px-icon>
            </div>
          </div>
          <div class="form-div">
            <px-row>
              <px-col :span="12">
                <px-form-item label="能耗指标" prop="code">
                  <div style="width: calc(100% - 160px)">
                    <px-tree-select
                      v-model="equipdata.code"
                      style="width: 100%"
                      placeholder="请选择"
                      :props="defaultProps"
                      :data="codeList"
                      :render-after-expand="false"
                    />
                  </div>

                  <!-- <px-input v-model="equipdata.energyConsumption" placeholder="请选择" clearable /> -->
                  <px-select v-model="equipdata.operator1" placeholder="运算符" style="width: 90px; margin-left: 10px" filterable>
                    <px-option v-for="dict in operatorList" :key="dict" :label="dict" :value="dict" />
                  </px-select>
                </px-form-item>
              </px-col>
              <px-col :span="12">
                <px-form-item label="单位转换系数" prop="coefficient">
                  <px-input-number
                    v-model="equipdata.coefficient"
                    :min="0"
                    :max="99999.99999"
                    controls-position="right"
                    :precision="4"
                    style="width: calc(100% - 160px)"
                    placeholder="请输入"
                    clearable
                  />
                  <px-select v-model="equipdata.operator2" placeholder="运算符" style="width: 90px; margin-left: 10px" filterable>
                    <px-option v-for="dict in operatorList2" :key="dict" :label="dict" :value="dict" />
                  </px-select>
                </px-form-item>
              </px-col>
              <px-col :span="12">
                <px-form-item label="排放因子" prop="emissionFactorName">
                  <px-input v-model="equipdata.emissionFactorName" style="width: calc(100% - 160px)" disabled placeholder="自动带出" clearable />
                  <px-button style="width: 90px; margin-left: 8px" type="primary" plain @click="selectyinzi()">选择</px-button>
                </px-form-item>
              </px-col>
              <px-col :span="12">
                <px-form-item label="发布年份版本" prop="historyRleaseYear">
                  <px-select
                    v-model="equipdata.historyRleaseYear"
                    placeholder="请选择发布年份"
                    clearable
                    style="width: calc(100% - 160px)"
                    filterable
                    @change="changeHistory"
                  >
                    <px-option v-for="(item, index) in historyList" :key="index" :label="item.releaseYear" :value="item.id" />
                  </px-select>
                </px-form-item>
              </px-col>
            </px-row>
          </div>
        </div>
      </px-form>
    </px-scrollbar>
    <px-dialog v-model="detailVisible" title="指标详情" width="1115px" :close-on-click-modal="false" align-center>
      <px-descriptions class="margin-top" title="" :column="2" border>
        <px-descriptions-item>
          <template #label>
            <div class="cell-item">指标名称</div>
          </template>
          {{ equipdata.name }}
        </px-descriptions-item>
        <px-descriptions-item>
          <template #label>
            <div class="cell-item">所属厂区</div>
          </template>
          {{ equipdata.level }}
        </px-descriptions-item>
        <px-descriptions-item>
          <template #label>
            <div class="cell-item">监控周期</div>
          </template>
          {{ equipdata.cycle }}
        </px-descriptions-item>
        <px-descriptions-item>
          <template #label>
            <div class="cell-item">执行时间</div>
          </template>
          {{ equipdata.startTime }} ~ {{ equipdata.endTime }}
        </px-descriptions-item>
        <px-descriptions-item>
          <template #label>
            <div class="cell-item">限值方式</div>
          </template>
          {{ equipdata.limitMethod }}
        </px-descriptions-item>
        <px-descriptions-item v-if="equipdata.limitMethod == '百分比'">
          <template #label>
            <div class="cell-item">限值百分比</div>
          </template>
          {{ equipdata.limitValue }}%
        </px-descriptions-item>
        <px-descriptions-item v-else>
          <template #label>
            <div class="cell-item">限值数值</div>
          </template>
          {{ equipdata.limitMin }}~{{ equipdata.limitMax }}
        </px-descriptions-item>
        <px-descriptions-item>
          <template #label>
            <div class="cell-item">修改人</div>
          </template>
          {{ equipdata.updateByName }}
        </px-descriptions-item>
        <px-descriptions-item>
          <template #label>
            <div class="cell-item">修改时间</div>
          </template>
          {{ equipdata.updateTime }}
        </px-descriptions-item>
        <px-descriptions-item>
          <template #label>
            <div class="cell-item">创建人</div>
          </template>
          {{ equipdata.createByName }}
        </px-descriptions-item>
        <px-descriptions-item>
          <template #label>
            <div class="cell-item">创建时间</div>
          </template>
          {{ equipdata.createTime }}
        </px-descriptions-item>
        <px-descriptions-item>
          <template #label>
            <div class="cell-item">计算公式</div>
          </template>
          [{{ equipdata.codeName }}]{{ equipdata.operator1 }}[{{ equipdata.coefficient }}]{{ equipdata.operator2 }}[{{
            equipdata.emissionFactorName
          }}]
        </px-descriptions-item>
      </px-descriptions>
    </px-dialog>
    <div v-if="addVisible" class="px-dialog-footer">
      <px-button @click="equipopenDetailcancel">取消</px-button>
      <px-button type="primary" @click="equipopenDetailsubmitForm(detailruleFormRef)">保存</px-button>
    </div>
  </div>
</template>

<script setup name="Dict" lang="ts">
defineOptions({
  name: "SystemDataDict"
});
// import { router } from "@/router";
import yearPicker from "./yearPicker.vue";
import { ArrowLeft } from "@px-ui/icons-vue";
import { useRoute } from "vue-router";
import { PxMessage, PxMessageBox } from "px-ui";
import { getCurrentInstance, ref, toRefs, reactive, onMounted } from "vue";
import { getToken } from "@/utils/auth";
import { queryChildByTypeCodeAndItemValue } from "@/api/waterClass";
import { queryListPagepull, queryDetailpull, addpull, updatepull, deletepull, queryListPageForOutbound } from "@/api/hazardousWasteS";
import { facilityquery, facilitysave, facilitydelete, facilitydetail, facilityedit } from "@/api/doubleCarbonManage/accountingList";
import { emissionFactorquery, getemissionFactorHistory } from "@/api/doubleCarbonManage/carbonAccounting";
import { queryDictData } from "@/api/common";
import {
  emissionIndicatorquery,
  emissionIndicatorsave,
  emissionIndicatoredit,
  emissionIndicatordelete,
  emissionIndicatordetail,
  emissionIndicatorgetOperator
} from "@/api/doubleCarbonManage/indexManage";
import { dictItemqueryListByTypeCode } from "@/api/waterClass";
const dateValue = ref<any>({ startYear: "", endYear: "" });
const updateStatisticYear: any = (startYear: number, endYear: number) => {
  console.log("选中年份", startYear, endYear);
  // queryParams.value.dateRange = [startYear.toString(), endYear.toString()];
  queryParams.value.startTime = `${startYear}-01-01 00:00:00`;
  queryParams.value.endTime = `${endYear}-12-31 23:59:59`;
  equipdata.value.dateRange = [`${startYear}-01-01`, `${endYear}-12-31`];
};
const settime = val => {
  console.log(val);
  queryParams.value.startTime = `${val[0]}-01 00:00:00`;
  queryParams.value.endTime = `${val[1]}-31 23:59:59`;

  equipdata.value.dateRange = [`${val[0]}-01`, `${val[1]}-31`];
};
const dateRange = ref<any>([]);
const setcycle = () => {
  equipdata.value.dateRange = [];
  console.log(`output->dateValue.value`, dateValue.value);
};
const jibenxinxiFlg = ref(true);
const jiqicanshuFlg = ref(true);
const setqingdanFlg = () => {
  jibenxinxiFlg.value = !jibenxinxiFlg.value;
};
const setjiqicanshuFlg = () => {
  jiqicanshuFlg.value = !jiqicanshuFlg.value;
};
const defaultProps = {
  children: "children",
  label: "name",
  value: "value"
};
const defaultTime: [Date, Date] = [new Date(2000, 1, 1, 0, 0, 1), new Date(2000, 1, 1, 23, 59, 59)];
const detailruleFormRef = ref();
let facDisabled = ref(false);
onMounted(() => {
  if (localStorage.getItem("facList")) {
    let faclist = JSON.parse(localStorage.getItem("facList"));
    if (faclist.length == 1) {
      facDisabled.value = true;
      queryParams.value.level = faclist[0].name;
      getList();
    } else if (faclist.length == 2) {
      facDisabled.value = false;
      queryParams.value.level = null;
      getList();
    }
  }
});
const { proxy }: any = getCurrentInstance();
function equipopenDetailcancel() {
  console.log(buttonTitle.value);
  if (buttonTitle.value == "新增") {
    if (
      equipdata.value.name != "" ||
      equipdata.value.level != "" ||
      equipdata.value.cycle != "" ||
      equipdata.value.limitValue != null ||
      equipdata.value.energyConsumption != "" ||
      equipdata.value.emissionFactorName != "" ||
      equipdata.value.name != "" ||
      equipdata.value.dateRange.length > 0
    ) {
      PxMessageBox.confirm("<p>取消将不保存当前录入信息返回上一页</p><p>确定取消吗？</p>", "温馨提示", {
        dangerouslyUseHTMLString: true,
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
        draggable: true
      })
        .then(async () => {
          addVisible.value = false;
          getList();
        })
        .catch(() => {});
    } else {
      addVisible.value = false;
      getList();
    }
  } else {
    addVisible.value = false;
    getList();
  }
}

const typeList = ref([]);
const progressVisible = ref(false);
const equipopen = ref(false);
const equipopenDetail = ref(false);
const fromdisable = ref(false);
const loading = ref(true);
const showSearch = ref(true);
const ids = ref([]);
const addVisible = ref(false);
const detailVisible = ref(false);
const innerVisible = ref(false);
const total = ref(0);
const total2 = ref(0);

// 图片是否上传完，是否可以保存
const buttonTitle = ref("");
const data = reactive({
  facList: [], // 厂区下拉框
  facList2: [],
  operatorList: [],
  cycleList: [],
  liquidList: [],
  rukuList: [],
  transportCompanyList: [],
  receiveCompanyList: [],
  typeIdList: [],
  categoryList: [],
  equipmentTypeList: [],
  positionList: [],
  selectRukuList: {},
  okselectRukuList: [],
  equipmentDeptList: [],
  modelIdList: [],
  form: {},
  wasteUnitoptions: [
    {
      value: "克",
      label: "克"
    },
    {
      value: "千克",
      label: "千克"
    },
    {
      value: "吨",
      label: "吨"
    }
  ],
  photoStatusFlag: false,
  fileStatusFlag: false,
  equipdata: {
    id: "",
    level: "",
    cycle: "",
    startTime: "",
    endTime: "",
    limitMethod: "百分比",
    limitValue: "",
    limitMin: "",
    limitMax: "",
    energyConsumption: "",
    emissionFactorId: "",
    emissionFactorName: "",
    historyRleaseYear: null,
    code: "",
    operator1: "×",
    coefficient: "",
    operator2: "×",
    createByName: "",
    updateByName: "",
    name: "",
    dateRange: []
  },
  queryParams: {
    orderByColumn: "",
    isAsc: "",
    name: "",
    level: "",
    cycle: "",
    orderBy: "",
    pageNum: 1,
    pageSize: 20
  },
  queryParams2: {
    orderByColumn: "",
    isAsc: "",
    emissionFactorName: "",
    factorSource: "",
    releaseYear: "",
    orderBy: "",
    pageNum: 1,
    pageSize: 20
  },
  rules: {
    name: [{ required: true, message: "指标名称不能为空", trigger: "blur" }],
    level: [{ required: true, message: "所属厂区不能为空", trigger: "change" }],
    cycle: [{ required: true, message: "计算周期不能为空", trigger: "change" }],
    dateRange: [{ required: true, message: "执行时间不能为空", trigger: "change" }],
    limitMethod: [{ required: true, message: "限值方式不能为空", trigger: "blur" }],
    limitValue: [{ required: true, message: "限值百分比不能为空", trigger: "blur" }],
    code: [{ required: true, message: "能耗指标不能为空", trigger: "change" }],
    coefficient: [{ required: true, message: "单位转换系数不能为空", trigger: "blur" }],
    emissionFactorName: [{ required: true, message: "排放因子不能为空", trigger: "blur" }],
    historyRleaseYear: [{ required: true, message: "排放因子版本不能为空", trigger: "change" }]
  },
  headers: {
    Authorization: "Bearer " + getToken().accessToken || ""
  },
  moduleName: "",
  dialogImageUrl: "",
  imageVisible: false,
  levelUnitList: [],
  energyList: [],
  categoryTypeList: [],
  SourceList: [],
  selectrow: null,
  codeList: []
});
const selectyinzi = () => {
  getRukuList();
  innerVisible.value = true;
};

const {
  codeList,
  liquidList,
  selectRukuList,
  queryParams,
  SourceList,
  levelUnitList,
  energyList,
  categoryTypeList,
  queryParams2,
  form,
  rules,
  equipdata,
  rukuList,
  selectrow,
  cycleList,
  operatorList,
  facList,
  facList2
} = toRefs(data);
const operatorList2 = ["×"];
const getqueryCategoryList = () => {
  emissionIndicatorgetOperator({}).then(res => {
    console.log(res);
    operatorList.value = res;
  });
  // queryDictData({ typeCode: "factoryArea" }).then(res => {
  //   facList.value = res;
  // });
  facList.value = [
    {
      itemName: "全厂",
      itemValue: "全厂"
    },
    {
      itemName: "创新中心一期",
      itemValue: "创新中心一期"
    },
    {
      itemName: "创新中心二期",
      itemValue: "创新中心二期"
    }
  ];
  facList2.value = [
    {
      itemName: "全厂",
      itemValue: "全厂"
    },
    {
      itemName: "创新中心一期",
      itemValue: "创新中心一期"
    },
    {
      itemName: "创新中心二期",
      itemValue: "创新中心二期"
    }
  ];
  dictItemqueryListByTypeCode({
    typeCode: "BICARBON_INDEX"
  }).then((response: any) => {
    console.log(response);
    codeList.value = response;
  });
  queryChildByTypeCodeAndItemValue({
    value: "EMISSION_FACTOR_SOURCE",
    typeCode: "BICARBON"
  }).then((response: any) => {
    SourceList.value = response;
  });
  cycleList.value = [
    {
      name: "年",
      value: "年"
    },
    {
      name: "月",
      value: "月"
    },
    {
      name: "日",
      value: "日"
    }
  ];
};
const handledelAddPosition = () => {
  equipdata.value.standardValueList.push({
    level: "",
    targetValue: null,
    benchmarkValue: null,
    complianceValue: null
  });
};
const handelRadio = row => {
  selectrow.value = row;
};
function handleDeleteceng(row) {
  PxMessageBox.confirm('是否确认删除"' + row.content + '"？', "温馨提示", {
    confirmButtonText: "确定",
    cancelButtonText: "取消",
    type: "warning",
    draggable: true
  })
    .then(async () => {
      equipdata.value.content = equipdata.value.content.filter(item => item != row);
      PxMessage({
        message: "删除成功",
        type: "success"
      });
      getList();
    })
    .catch(() => {});
}
const addsave = () => {};
const clearnum = () => {};
getqueryCategoryList();
function getRukuList() {
  selectrow.value = null;
  loading.value = true;

  emissionFactorquery(queryParams2.value).then((response: any) => {
    rukuList.value = response.data;
    total2.value = response.total;
    loading.value = false;
  });
}

function getList() {
  loading.value = true;
  emissionIndicatorquery(queryParams.value).then((response: any) => {
    typeList.value = response.data;
    total.value = response.total;
    loading.value = false;
  });
}
const removechukuList = () => {
  localStorage.removeItem("chukuList");
};
/** 取消按钮 */

/** 表单重置 */
function reset() {
  form.value = {
    id: undefined,
    dictionaryName: undefined,
    dictionaryType: undefined,
    status: "VALID",
    remarks: undefined
  };
  proxy.resetForm("dictRef");
}
/** 搜索按钮操作 */
function handleQuery(type) {
  if (type == "search") {
    queryParams.value.pageNum = 1;
  }
  getList();
}
function handleQuery2(type) {
  if (type == "search") {
    queryParams2.value.pageNum = 1;
  }
  getRukuList();
}
/** 重置按钮操作 */
function resetQuery() {
  queryParams.value = {
    pageNum: queryParams.value.pageNum,
    pageSize: queryParams.value.pageSize,
    orderByColumn: "",
    isAsc: "",
    name: "",
    level: "",
    cycle: "",
    orderBy: ""
  };
  if (localStorage.getItem("facList")) {
    let faclist = JSON.parse(localStorage.getItem("facList"));
    if (faclist.length == 1) {
      facDisabled.value = true;
      queryParams.value.level = faclist[0].name;
      getList();
    } else if (faclist.length == 2) {
      facDisabled.value = false;
      queryParams.value.level = null;
      getList();
    }
  }
  equipdata.value.dateRange = [];
  handleQuery("reset");
}

function resetQuery2() {
  queryParams2.value = {
    pageNum: queryParams2.value.pageNum,
    pageSize: queryParams2.value.pageSize,
    orderByColumn: "",
    isAsc: "",
    emissionFactorName: "",
    factorSource: "",
    releaseYear: "",
    orderBy: "",
    status: "",
    excludeInboundNumber: []
  };
  // equipdata.value.dateRange = [];
  handleQuery2("reset");
}
const historyList = ref([]);

/** 新增按钮操作 */
function handleAdd() {
  historyList.value = [];
  buttonTitle.value = "新增";
  addVisible.value = true;
  equipdata.value = {
    id: "",
    level: "",
    cycle: "日",
    startTime: "",
    endTime: "",
    limitMethod: "百分比",
    limitValue: null,
    limitMin: null,
    limitMax: null,
    energyConsumption: "",
    emissionFactorId: "",
    emissionFactorName: "",
    historyRleaseYear: null,
    code: "",
    operator1: "×",
    coefficient: "",
    operator2: "×",
    createByName: "",
    updateByName: "",
    name: "",
    dateRange: []
  };
  if (localStorage.getItem("facList")) {
    let faclist = JSON.parse(localStorage.getItem("facList"));
    if (faclist.length == 1) {
      facDisabled.value = true;
      equipdata.value.level = faclist[0].name;
    } else if (faclist.length == 2) {
      queryParams.value.level = faclist.filter(item => item.code == localStorage.getItem("facCode"))[0].name;
      getList();
    }
  }
  selectrow.value = null;
}
const handleDetail = async val => {
  detailVisible.value = true;
  const data = await emissionIndicatordetail({ id: val });
  //console.log(data);

  equipdata.value = data;
};

const handleEditor = async val => {
  historyList.value = [];
  equipdata.value.historyRleaseYear = null;
  buttonTitle.value = "编辑";
  addVisible.value = true;
  const data = await emissionIndicatordetail({ id: val });

  equipdata.value = { ...data, historyRleaseYear: null };

  selectrow.value = null;
  equipdata.value.dateRange = [data.startTime, data.endTime];
  dateRange.value = [data.startTime.slice(0, 7), data.endTime.slice(0, 7)];
  dateValue.value = { startYear: data.startTime.slice(0, 4), endYear: data.endTime.slice(0, 4) };
  getHistory(equipdata.value.emissionFactorName, equipdata.value.emissionFactorId);
};
/** 多选框选中数据 */
function handleSelectionChange2(selection) {
  console.log(selection);
  selectRukuList.value = selection;
}

// const addRukudetails = () => {
//   equipdata.value.details = [...equipdata.value.details, ...selectRukuList.value];
//   let seenIds = new Set();
//   let uniqueArr = [];
//   equipdata.value.details.forEach(obj => {
//     if (!seenIds.has(obj.inboundNumber)) {
//       uniqueArr.push(obj);
//       seenIds.add(obj.inboundNumber);
//     }
//   });
//   equipdata.value.details = [];
//   if (setChukuList(uniqueArr) == true) {
//     progressVisible.value = false;
//     equipdata.value.details = uniqueArr;
//   }
// };

let setChukuList = uniqueArr => {
  if (uniqueArr.length === 0) {
    PxMessage({
      message: "请选择要出库的数据",
      type: "error"
    });
    return false;
  }
  const firstname = uniqueArr[0].wasteName;
  for (let i = 1; i < uniqueArr.length; i++) {
    if (uniqueArr[i].wasteName != firstname) {
      PxMessage({
        message: "请选择相同的废弃物",
        type: "error"
      });
      return false;
    }
  }
  return true;
};

const handleDeleteRuku = row => {
  // console.log(row);
  equipdata.value.details = equipdata.value.details.filter(item => item != row);
};
const saveYinziku = () => {
  if (selectrow.value != null) {
    equipdata.value.emissionFactorId = selectrow.value.id;
    equipdata.value.emissionFactorName = selectrow.value.name;
    innerVisible.value = false;
    // resetFrom();
    detailruleFormRef.value.validateField("emissionFactorName");
    // 增加查询排放因子
    getHistory(equipdata.value.emissionFactorName);
  } else {
    PxMessage({
      message: `请选择排放因子`,
      type: "error"
    });
  }
  //selectrow
};
const changeHistory = (val: number) => {
  equipdata.value.emissionFactorId = val;
};
async function getHistory(name: string, id?: number) {
  const params = {
    name,
    pageNum: 1,
    pageSize: 500
  };
  const res = await getemissionFactorHistory(params);
  if (!res) return;
  historyList.value = res.data;
  equipdata.value.historyRleaseYear = id || historyList.value[0].id;
}
/** 提交按钮 */
const resetFrom = () => {
  detailruleFormRef.value.validateField("name");
  detailruleFormRef.value.validateField("level");
  detailruleFormRef.value.validateField("cycle");
  detailruleFormRef.value.validateField("dateRange");
  detailruleFormRef.value.validateField("limitMethod");
  detailruleFormRef.value.validateField("limitValue");
  detailruleFormRef.value.validateField("energyConsumption");
  detailruleFormRef.value.validateField("emissionFactorName");
  detailruleFormRef.value.validateField("historyRleaseYear");
};

const equipopenDetailsubmitForm = async (formEl: any) => {
  if (!formEl) return;
  await formEl.validate(async valid => {
    if (valid) {
      console.log(equipdata);
      const params = {
        level: equipdata.value.level,
        cycle: equipdata.value.cycle,
        startTime: equipdata.value.dateRange[0] + " " + "00:00:00",
        endTime: equipdata.value.dateRange[1] + " " + "23:59:59",
        limitMethod: equipdata.value.limitMethod,
        limitValue: equipdata.value.limitMethod == "数值" ? null : equipdata.value.limitValue,
        limitMin: equipdata.value.limitMethod == "数值" ? equipdata.value.limitMin : null,
        limitMax: equipdata.value.limitMethod == "数值" ? equipdata.value.limitMax : null,
        emissionFactorId: equipdata.value.emissionFactorId,
        emissionFactorName: equipdata.value.emissionFactorName,
        energyConsumption: equipdata.value.energyConsumption,
        code: equipdata.value.code,
        operator1: equipdata.value.operator1,
        coefficient: equipdata.value.coefficient,
        operator2: equipdata.value.operator2,
        createByName: JSON.parse(localStorage.getItem("userInfo")).username,
        updateByName: JSON.parse(localStorage.getItem("userInfo")).username,
        name: equipdata.value.name
      };
      if (buttonTitle.value == "新增") {
        if (equipdata.value.limitMethod == "数值") {
          if (
            equipdata.value.limitMin == "" ||
            equipdata.value.limitMax == "" ||
            equipdata.value.limitMin == null ||
            equipdata.value.limitMax == null
          ) {
            PxMessage({
              message: `请输入数值`,
              type: "error"
            });
            return false;
          } else {
            emissionIndicatorsave(params).then((response: any) => {
              PxMessage({
                message: `${buttonTitle.value == "新增" ? "添加成功" : "修改成功"}`,
                type: "success"
              });
              resetQuery();
              addVisible.value = false;
            });
            getList();
          }
        } else {
          emissionIndicatorsave(params).then((response: any) => {
            PxMessage({
              message: `${buttonTitle.value == "新增" ? "添加成功" : "修改成功"}`,
              type: "success"
            });
            resetQuery();
            addVisible.value = false;
          });
          getList();
        }
      } else {
        const params2 = {
          id: equipdata.value.id,
          level: equipdata.value.level,
          cycle: equipdata.value.cycle,
          startTime: equipdata.value.dateRange[0] + " " + "00:00:00",
          endTime: equipdata.value.dateRange[1] + " " + "23:59:59",
          limitMethod: equipdata.value.limitMethod,
          limitValue: equipdata.value.limitMethod == "数值" ? null : equipdata.value.limitValue,
          limitMin: equipdata.value.limitMethod == "数值" ? equipdata.value.limitMin : null,
          limitMax: equipdata.value.limitMethod == "数值" ? equipdata.value.limitMax : null,
          code: equipdata.value.code,
          operator1: equipdata.value.operator1,
          coefficient: equipdata.value.coefficient,
          operator2: equipdata.value.operator2,
          emissionFactorId: equipdata.value.emissionFactorId,
          emissionFactorName: equipdata.value.emissionFactorName,
          calculationFormulaEmission: equipdata.value.calculationFormulaEmission,
          energyConsumption: equipdata.value.energyConsumption,
          operator: equipdata.value.operator,
          name: equipdata.value.name
        };
        if (equipdata.value.limitMethod == "数值") {
          if (
            equipdata.value.limitMin == "" ||
            equipdata.value.limitMax == "" ||
            equipdata.value.limitMin == null ||
            equipdata.value.limitMax == null
          ) {
            PxMessage({
              message: `请输入数值`,
              type: "error"
            });
            return false;
          } else {
            emissionIndicatoredit(params2).then((response: any) => {
              PxMessage({
                message: `${buttonTitle.value == "新增" ? "添加成功" : "修改成功"}`,
                type: "success"
              });
              resetQuery();
              addVisible.value = false;
            });
            getList();
          }
        } else {
          emissionIndicatoredit(params2).then((response: any) => {
            PxMessage({
              message: `${buttonTitle.value == "新增" ? "添加成功" : "修改成功"}`,
              type: "success"
            });
            resetQuery();
            addVisible.value = false;
          });
          getList();
        }
      }
    }
  });
};
/** 删除按钮操作 */
function handleDelete(row) {
  PxMessageBox.confirm("是否确认删除？", "温馨提示", {
    confirmButtonText: "确定",
    cancelButtonText: "取消",
    confirmButtonClass: "px-button--danger",
    type: "warning",
    draggable: true
  })
    .then(async () => {
      const data = await emissionIndicatordelete({ id: row.id });
      PxMessage({
        message: "删除成功",
        type: "success"
      });
      getList();
    })
    .catch(() => {});
}

/** 导出按钮操作 */
function handleExport() {
  const dictIds = [];
  dictIds.push(...ids.value);
  const params = { ids: dictIds };
  proxy.download("post", "/operation/api/v1/water/hazardWasteOut/export", params, "危险废弃物出库.xlsx");
}
</script>
<style scoped lang="scss">
.addEquip {
  position: absolute;
  top: 0;
  top: 5px;
  left: 0;
  width: calc(100% - 48px);
  height: calc(100% - 40px);
  margin: 24px;
  background: white;
}

.editorEquip {
  position: absolute;
  top: 0;
  top: 5px;
  left: 0;
  width: calc(100% - 48px);
  height: calc(100% - 40px);
  margin: 24px;
  background: white;
}

.px-dialog-footer {
  position: absolute;
  bottom: 0;
  left: 0;
  z-index: 2002;
  width: 100%;
  height: 50px;
  padding-top: 10px;
  padding-right: 34px;
  text-align: right;
  background: white;
  box-shadow: 0 0 10px 0 rgb(0 0 0 / 16%);
}

.card-header {
  min-height: 40px;
  padding: 14px 15px 7px !important;
  cursor: pointer;
  user-select: none;
  background: #e7eefb;
}

.card-title {
  float: left;
  line-height: 14px;
}

.card-main {
  float: left;
  margin: -3px 8px 0 5px;
  cursor: pointer;
}

.box-card1 {
  width: calc(100% - 48px);
  margin: 24px;
  border: 1px solid #dfdfdf;
  border-radius: 4px;
}

.box-card2 {
  width: calc(100% - 48px);
  margin: 24px;
  overflow: hidden;
  border: 1px solid #dfdfdf;
  border-radius: 4px;
}

.box-card3 {
  width: calc(100% - 48px);
  margin: 24px;
  overflow: hidden;
  border: 1px solid #dfdfdf;
  border-radius: 4px;
}

.box-card4 {
  width: calc(100% - 48px);
  height: 261px;
  margin: 24px;
  overflow: hidden;
  border: 1px solid #dfdfdf;
  border-radius: 4px;
}

.demo-form-inline {
  .px-input {
    --px-input-width: calc(100% - 100px);
  }

  .px-form-item {
    width: 100%;
  }

  .px-textarea__inner {
    width: calc(100% - 100px) !important;
  }

  .px-form-item__label {
    font-weight: 400 !important;
  }
}

.form-div {
  padding: 24px;

  .px-row {
    margin-bottom: 16px;
  }
}

.px-icon {
  font-size: 16px !important;
}

:deep(.px-tabs--top .px-tabs__item.is-top.is-active) {
  border: none;

  .pane-bottom {
    line-height: 30px;
    border-bottom: 2px solid #3b82f6;
  }
}

:deep(.px-tabs .px-tabs__item) {
  .pane-bottom {
    line-height: 30px;
  }
}

.pane-line {
  position: absolute;
  top: 12px;
  right: 0;
  height: 15px;
  color: #dcdcdc;
  border-left: 1px solid #dcdcdc;
}

:deep(.custom-form-ui .px-form-item) {
  width: 250px !important;
}

.filename {
  position: absolute;
  bottom: -30px;
  width: 96px;
  overflow: hidden;
  color: rgb(166 167 172);
  text-overflow: ellipsis;
  white-space: nowrap;
}

:deep(.px-descriptions__label.px-descriptions__cell.is-bordered-label) {
  width: 166px;
  background: #e7eefb;
  border: 1px solid #dfdfdf;
}

:deep(.px-descriptions__body .px-descriptions__table.is-bordered .px-descriptions__cell) {
  border: 1px solid #dfdfdf;
}

.cell-item {
  text-align: right;
}

:deep(.px-table__header) {
  thead {
    tr {
      background-color: #e7eefb !important;

      th {
        font-size: 13px;
        font-weight: bold;
        color: #000;
        background-color: #e7eefb !important;
      }
    }
  }
}

:deep(.px-table--isfixedHeader .px-table__header-wrapper .px-table-fixed-column--right) {
  background-color: #e7eefb !important;
}

:deep(.px-radio.px-radio--large) {
  height: 32px;
}

:deep(.px-input-number .px-input__inner) {
  text-align: left;
}

:deep(.px-input-number.is-controls-right .px-input__wrapper) {
  padding-left: 8px;
}
</style>
